package com.huanwei.rizhi;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import com.huanwei.mini.R;
import com.huanwei.mini.adapter.RiZhiListAdapter;
import com.huanwei.mini.http.API;
import com.huanwei.mini.http.RizhiList;
import com.huanwei.mini.http.TZ;
import com.huanwei.mini.utils.JSONUtils;
import com.huanwei.mini.utils.Okhttp;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RiZhiListActivity extends AppCompatActivity {

    @BindView(R.id.lv)
    ListView lv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rizhi);
        ButterKnife.bind(this);
        setdata();
    }


    RiZhiListAdapter demoAdapter;

    private void setdata() {
        demoAdapter = new RiZhiListAdapter();
        lv.setAdapter(demoAdapter);

        API.Getlist(RiZhiListActivity.this, new Okhttp.Objectcallback() {
            @Override
            public void onsuccess(String st) {

                Log.e("12123", "1111" + st);
                RizhiList tz = JSONUtils.parseJSON(st, RizhiList.class);
                if (tz.getError()==0) {
                    List<RizhiList.SdataEntity>    data = tz.getSdata();

                    demoAdapter.addItem(data);
                } else {
                    Toast.makeText(RiZhiListActivity.this, "获取数据失败！"    , Toast.LENGTH_SHORT).show();
                }


            }


            @Override
            public void onFalia(int code, String errst) {

                Toast.makeText(RiZhiListActivity.this, "网络错误" + errst, Toast.LENGTH_SHORT).show();
            }
        });

    }
}
